<!--登录页-->
<template>
  <div class="login_container">
    <div class="login_title">建筑能源管理平台</div>
    <div class = "login_box">
      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="80px" class = "login_form">
        <!-- 用户名   -->
        <el-form-item prop = "username" label="用户名：">
          <el-input v-model="username" prefix-icon="iconfont icon-user"></el-input>
        </el-form-item>
        <!-- 密码-->
        <el-form-item prop="password" label="密码：">
          <el-input v-model="password" prefix-icon="iconfont icon-3702mima" type = "password"></el-input>
        </el-form-item>
        <!-- 按钮区域 -->
        <el-form-item class="btns">
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>

    </div>
  </div>
</template>

<script>
    export default {
        name: "Login",
      data(){
          return{
            username:'admin',
            password:'123456',

            // 这是登录表单的数据绑定对象
            loginFormData:[],
            // 这是表单的验证规则对象
            loginFormRules: {
              // 验证用户名是否合法
              username: [
                { required: true, message: '请输入登录名称', trigger: 'blur' },
                { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
              ],
              // 验证密码是否合法
              password: [
                { required: true, message: '请输入登录密码', trigger: 'blur' },
                { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
              ]
            }
          }
      },
      methods:{
        login() {
            this.axios.get('/api/module0/LoginData').then(resp=>{

              this.loginFormData = resp.data.list;
              if(this.loginFormData.username==this.username&&this.loginFormData.password==this.password){
                this.$message.success('登录成功');
                this.$router.push("/home");
              }
            else{
                return this.$message.error('登录失败！');
              }
            })
          }

      }
    }
</script>

<style>
  html,body{
    height: 100%;
    padding: 0;
    margin: 0;
  }
  .login_container{
    height: 100%;
    background-image: linear-gradient(to top, #30cfd0 0%, #330867 100%);
  }
  .login_title{
    font-size: 55px;
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .login_box{
    background-color: rgba(0,0,0,0.4);
    width: 450px;
    height: 300px;
    border-radius: 5px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border: 1px solid #cccccc;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
    display: flex;
    align-content: center;
  }
  .login_form{
    margin-top: 50px;
    width: 80%;
    margin-left: 20px;
  }
  .btns{
    display: flex;
    justify-content: center;
  }
</style>
